package com.mrjoew.weekend.services.impl.sys;

import com.mrjoew.weekend.constants.SysRoleConstant;
import com.mrjoew.weekend.entities.po.SysRolePO;
import com.mrjoew.weekend.repositories.sys.SysRoleRepository;
import com.mrjoew.weekend.services.sys.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.transaction.Transactional;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author Christopher Jones
 * @ClassName SysRoleServiceImpl
 * @explain
 * @date 2020/6/21 0021 14:20
 */
@Transactional
@Service
public class SysRoleServiceImpl implements SysRoleService {

    private final SysRoleRepository sysRoleRepository;

    public SysRoleServiceImpl(SysRoleRepository sysRoleRepository) {
        this.sysRoleRepository = sysRoleRepository;
    }

    @Override
    public String[] anonymous() {
        Set<SysRolePO> pos = sysRoleRepository.findAllByName(SysRoleConstant.ANONYMOUS);
        if (!CollectionUtils.isEmpty(pos)) {
            Set<String> urls = pos.stream().map(SysRolePO::getUrl).collect(Collectors.toSet());
            return urls.toArray(new String[]{});
        }

        return null;
    }
}
